<!--
 * @Description: 
 * @Version: 2.0
 * @Autor: jerry.zzy
 * @Date: 2021-05-25 16:29:04
 * @LastEditors: jerry.zzy
 * @LastEditTime: 2021-05-25 16:52:36
-->
<template>
  <div>
    <a-modal
      title="货架信息"
      :visible="goodsShelvesTag"
      @ok="handleOk"
      width="50%"
      @cancel="handleCancel"
    >
      <a-table
        rowKey="key"
        :columns="columns"
        :data-source="dataSource"
        :row-selection="{
          selectedRowKeys: orderSelectedRowKeys,
          onChange: orderSelectChange,
        }"
      >
      </a-table>
    </a-modal>
  </div>
</template>


<script>
import { ChanChengPinRuKuHttp } from "@/services/modules/RuKuGuGuanLi/ChanChengPinRuKu";
const cprkHttp = new ChanChengPinRuKuHttp(); // 采购入库
const columns = [
  {
    title: "序号",
    dataIndex: "key",
    key: "key",
  },
  {
    title: "货架编码",
    dataIndex: "shelvesCode",
    key: "shelvesCode",
  },
];
export default {
  props: {
    // goodsShelvesTag 用来显示 弹窗是否打开
    goodsShelvesTag: {
      type: Boolean,
    },
    tableKey: {
      type: Number,
    },
  },

  mounted() {},

  watch: {},

  data() {
    return {
      columns,
      dataSource: [],
      orderSelectedRowKeys: [],
      goodsShelvesList: [], // 物品货架列表
    };
  },

  methods: {
    // 货架编号选择
    orderSelectChange(selectedRowKeys, selectedRows) {
      console.log("selectedRowKeys", selectedRowKeys);
      this.orderSelectedRowKeys = selectedRowKeys;

      console.log("选中的所有项为", selectedRows);
      this.goodsShelvesList = selectedRows;
    },

    // 获取货架信息
    getGoodShelveInfo() {
      this.dataSource = [];

      this.dataSource.push();

      cprkHttp.getSelectShelvesByShedId().then((res) => {
        console.log("获取货架信息:::::", res);

        for (let i = 0; i < res.result.length; i++) {
          let data = {
            key: i+1,
            shelvesCode: res.result[i].shelvesCode,
          };
          this.dataSource.push(data);
          console.log(this.dataSource);
        }
      });
    },

    handleOk() {
      this.$emit("get-goodShelveInfo", this.tableKey, this.goodsShelvesList);
      this.orderSelectedRowKeys = [];
    },

    handleCancel() {
      this.$emit("close-goodShelveInfo");
    },
  },
};
</script>

<style lang="less" scoped>
</style>
